/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Hashtable;

/**
 *
 * @author dlvcpe
 */
public class ServiceLocator {
	
	private static Hashtable cache = new Hashtable();

	public static Object getObject(String name){
		if (cache.containsKey(name)){
			return cache.get(name);
		}else{
			try {
				Class classe = Class.forName(name);
				Method metodo = classe.getMethod("getInstancia", new Class[]{});
				Object retorno = metodo.invoke(new Object(), new Object[]{});
				cache.put(name, retorno);
				return retorno;
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SecurityException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NoSuchMethodException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}
	
}

